// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.

const { ipcRenderer } = require("electron/renderer");
const { BrowserWindow,dialog } = require('electron').remote


window.addEventListener('DOMContentLoaded',() => {
  // const nodeverionp = document.querySelector('#node-version');
  // nodeverionp.innerHTML = process.versions['node'];

  const initResult = FZK_FC2_LIB.fzk_fc_init();

  console.log('initResult',initResult)

  const connectBtn = document.querySelector('#connectBtn');
  connectBtn.addEventListener('click',() => {
    //连接发卡器
    const connectResultCode = FZK_FC2_LIB.fzk_fc_connect();
    if(connectResultCode == 0) {
      dialog.showMessageBox({
        type:'info',
        title:'提示',
        detail:'连接成功'
      })
    } else {
      dialog.showMessageBox({
        type:'error',
        title:'提示',
        detail:'连接失败,请重试'
      })
    }
  })

  const readeCardUidBtn = document.querySelector('#readCardUID');
  readeCardUidBtn.addEventListener('click',()=> {
     const cardUid = FZK_FC2_LIB.fzk_fc_getUid();

     if (cardUid === 0) {
       dialog.showMessageBox({
         type:'error',
         title:'提示',
         detail:'读取卡片UID失败'
       })
       return
     }

     const uidIdInput = document.querySelector('#UidInput');
     uidIdInput.setAttribute('value',cardUid);
  })


  const recyleCardBtn = document.querySelector('#recyleCard');
  recyleCardBtn.addEventListener('click',() => {
    const recyleResult = FZK_FC2_LIB.fzk_fc_recycle();
    console.log('recyleResult',recyleResult);
    if(recyleResult === 0) {
      dialog.showMessageBox({
        title:'提示',
        detail:'回收卡片成功'
      })
    }
  })

})